package com.speechb.modules.system.admin.controller;

import com.speechb.modules.system.admin.controller.base.BaseController;
import com.speechb.modules.system.admin.service.IComService;
import com.speechb.modules.system.entity.CommonModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : llj
 * @version :2.1.0
 * @date : 2021/2/15 22:15
 */
@RestController
@RequestMapping("${adminRoot}/com")
public class ComController extends BaseController {
    @Autowired
    IComService comService;
    @PostMapping("/update")
    public void update() {
        String id = getPara("pk[pk]");
        String name = getPara("name");
        String value = getPara("value");
        String tableName = getPara("pk[table_name]");
        CommonModel commonModel = new CommonModel();
        commonModel.setId(id);
        commonModel.setKey(name);
        commonModel.setValue(value);
        commonModel.setTable_name(tableName);
        int updateSize = comService.update(commonModel);
        if (updateSize > 0) {
            render();
            return;
        }
        renderFail();
    }

    @DeleteMapping("/delete")
    public void delete() {
        String id = getPara("id");
        String tableName = getPara("table_name");
        CommonModel commonModel = new CommonModel();
        commonModel.setId(id);
        commonModel.setTable_name(tableName);
        int deleteSize = comService.delete(commonModel);
        if (deleteSize > 0) {
            render();
            return;
        }
        renderFail();
    }
}
